package com.dal.log.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Search {
 
	/* 请完成下面这个函数，实现题目要求的功能 */
	/* 当然，你也可以不按照下面这个模板来作答，完全按照自己的想法来 ^-^ */
	/****************************** 开始写代码 ******************************/
	static String[] doFilter(List<User> source, String filter) {
		// 输入字符串转字符数组
		char[] charArr = filter.toCharArray(); // 注意返回值是char数组
 
		String[] result = null;
		result = new String[source.size()];
		int[] B = new int[source.size()];
		int[] b = new int[source.size()];
 
		int num = 0;
		for (int i = 0; i < source.size(); i++) {
			// 数据源字符串转字符数组
			char[] charSource = source.get(i).getUsername().toCharArray();
 
			// 全部置1
			for (int x = 0; x < 9; x++) {
				b[x] = 1;
			}
 
			int m = 0;
			int t = 0;
			for (int j = 0; j < charSource.length; j++) {
 
				if (j >= charArr.length) {
					j = charArr.length - 1;
				}
				if (m >= charSource.length) {
					break;
				}
				for (; m < charSource.length; m++) {
					if (charSource[m] == charArr[j]) {
						t = t + 1;
 
						b[m] = 1;
						m = m + 1;
						break;
					}
					if (charSource[m] != charArr[j]) {
 
						b[m] = 0;
 
					}
				}
 
			}
 
			if (t == charArr.length) {
 
				result[num] = source.get(i).getUsername();
				B[num] = Num(b);// b[i];
				num++;
 
			}
 
		}
 
		String T = null;
		int tt = 0;
		for (int result_i = 0; result_i < result.length; result_i++) {
			for (int result_j = result_i + 1; result_j < result.length; result_j++) {
				if (B[result_j] > B[result_i]) {
					T = result[result_j];
					result[result_j] = result[result_i];
					result[result_i] = T;
 
					tt = B[result_j];
					B[result_j] = B[result_i];
					B[result_i] = tt;
				}
			}
		}
 
		return result;
 
	}
 
	/****************************** 结束写代码 ******************************/
 
	public static int Num(int[] b) {
		int byteb = 0;
		int num = 0;
		for (int y = 0; y < 9; y++) {
			byteb = (int) (b[y] * Math.pow(10, 8 - y));
			num += byteb;
 
		}
		return num;
 
	}
 
	public static void main(String[] args) {


 
		String[] _source = { "AB", "ABC", "ACB", "ABCD", "ADBCF", "ABDCF", "ABDC", "ABDFCG", "ABDFGC", "ABDEFG",
				"GABCEFG" };

		List<User> users = new ArrayList<>();
		for (int i = 0; i < 15; i++) {
			User user = new User();
			user.setUsername("健"+i);
			user.setAge(i);
			users.add(user);
		}


		Scanner in = new Scanner(System.in);
		String _filter;
		try {
			_filter = in.nextLine();
		} catch (Exception e) {
			_filter = null;
		}
 
		String[] res = doFilter(users, _filter);
		for (int res_i = 0; res_i < res.length; res_i++) {
 
			if ((res[0] == null) && (res[res.length - 1] == null)) {
				System.out.println("-1");
				break;
			}
			if (res[res_i] == null)
				break;
			System.out.println(String.valueOf(res[res_i]));
		}
 
	}
}